<?php
/**
 * ImpSoft Base Model
 * All other models extend this guy
 * 
 * @package ImpSoft
 * @subpackage ImpSoft Models
 * @copyright Luke Visinoni (luke.visinoni@gmail.com)
 * @author Luke Visinoni (luke.visinoni@gmail.com)
 * @license GNU Lesser General Public License
 */
class ImpSoft_Db_Table extends Zend_Db_Table {

    protected $_required = array(); // put required fields in here
    /**
     * This method allows for the model to provide valiation rules specific to the model.
     * A lot of the time there are more rules than simply the ones that validate information
     * related to the model, even if you are actually editing a model, so this allows that separation
     *
     * @return A_Rule_Set Even if you have no rules to add, this should still return a rule set
     */
    public function getRules() {
    
        return new Q_Rule_Set();
    
    }
    /**
     * This method allows for the model to provide filters specific to the model.
     * A lot of the time there are more filters than simply the ones that filter information
     * related to the model, even if you are actually editing a model, so this allows that separation
     *
     * @return A_Filter_Set Even if you have no rules to add, this should still return a filter set
     */
    public function getFilters() {
    
        return new Q_Filter_Set();
    
    }
    /**
     * This method allows for the model to provide filters specific to the model.
     * A lot of the time there are more filters than simply the ones that filter information
     * related to the model, even if you are actually editing a model, so this allows that separation
     *
     * @return A_Filter_Set Even if you have no rules to add, this should still return a filter set
     */
    public function getRequired() {
    
        return $this->_required;
    
    }
    /**
     * Pass in a select statement and it will attempt to find a row. If it can't find a row, it will return
     * a blank (new) one.
     *
     * @param Zend_Db_Select
     * @return Zend_Db_Table_Row
     */
    public function fetchOrCreate(Zend_Db_Select $select) {
    
        $select->limit(1,1);
        if (!$row = $this->fetchRow($select)) {
            $row = $this->createRow();
        }
        return $row;
    
    }
    
    public function getColumns() {
    
        return array_keys($this->getAdapter()->describeTable($this->_name));
    
    }
	/**
	 * Returns an empty array with column names as keys and empty values. You may optionally
	 * provide a prefix and/or suffix and it will be used on the keys.
	 */
	public function getArraySkeleton($prefix = '', $suffix = '') {
	
		$row = $this->createRow()->toArray();
		$prefixedrow = array();
		foreach ($row as $key => $val) {
			$key = $prefix . $key . $suffix;
			$prefixedrow[$key] = $val;
		}
		return $prefixedrow;
	
	}

}